package org.core.tliaswebmanagement.mapper;

import org.apache.ibatis.annotations.*;
import org.core.tliaswebmanagement.pojo.Emp;
import org.core.tliaswebmanagement.pojo.EmpQueryParam;

import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
//原始分页查询
//    @Select("select count(*) from emp e left join dept d on e.dept_id=d.id;")
//    public Long count();

//    @Select("select e.*,d.name as deptName from emp e left join dept d on e.dept_id=d.id " +
//            "order by e.update_time desc limit #{start},#{pageSize};")
//    public List<Emp> list(@Param("start") Integer start, @Param("pageSize") Integer pageSize);//官方框架编译时保留形参名，阿里云不会

    //使用PageHelper实现分页查询会在末尾拼接limit,所以sql语句末尾不能有分号
    //@Select("select e.*,d.name as deptName from emp e left join dept d on e.dept_id=d.id order by e.update_time desc")
//    public List<Emp> list(@Param("name") String name,
//                          @Param("gender") Integer gender,
//                          @Param("begin") LocalDate begin,
//                          @Param("end") LocalDate end);

    public List<Emp> list(EmpQueryParam param);

    @Options(useGeneratedKeys = true,keyProperty = "id")//插入成功后返回主键
    @Insert("insert into emp(username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) " +
    "values (#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    public void insert(Emp emp);

    void deleteByIds(@Param("ids") List<Integer> ids);

    Emp getById(@Param("id") Integer id);

    void updateById(Emp emp);

    //@MapKey is required 是MybatisX的误报
    List<Map<String,Object>> countEmpJobData();

    List<Map<String, Object>> countEmpGenderData();

    @Select("select * from emp where dept_id=#{id}")
    Collection<Object> selectByDeptId(Integer id);

    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp selectByUsernameAndPassword(Emp emp);

    @Select("select * from emp")
    List<Emp> findAll();
}